package com.cplatform.cat.java8;

import com.cplatform.cat.App;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Supplier;

public class LambdaPre {
    public static void main(String[] args) {
//        processFile((br)-> {
//            try {
//                return br.readLine()+br.readLine();
//            } catch (IOException e) {
//                e.printStackTrace();
//                return null;
//            }
//        });
//        List<String> str = Arrays.asList("a","b","A","B");
//        str.sort(String::compareTo);
//        Function<String,Integer>  stringtoInteger = Integer::parseInt;
//        BiPredicate<List<String>,Integer> contains = List::contains;
        Apple apple = new Apple(150,"黄色");
        Supplier<String>  stringSuppliers= apple::getColor;
        String a = stringSuppliers.get();
        System.out.println(a);
        List<Integer> weights = Arrays.asList(7, 3, 4, 10);
        List<Apple> apples = map(weights,Apple::new);
        System.out.println(apples);
    }
    //
    public static List<Apple> map(List<Integer> weights,
                                  Function<Integer,Apple> mapFunction){
        List<Apple> result = new ArrayList<>();
        weights.forEach((weight)-> result.add(mapFunction.apply(weight)));
        return result;

    }
    public static String processFile(Function<BufferedReader,String> function){
        try(BufferedReader bufferedReader = new BufferedReader(new FileReader("data.txt"))) {
            return function.apply(bufferedReader);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}
